using System.Collections.Generic;

namespace LibraryHub.Core.Models.User
{
    /// <summary>
    /// Custom comparer for the UserModel class
    /// </summary>
    public class UserModelIdComparer : IEqualityComparer<UserModel>
    {
        // Products are equal if their names and product numbers are equal.
        public bool Equals(UserModel x, UserModel y)
        {
            // Check whether the compared objects reference the same data.
            if (ReferenceEquals(x, y))
            {
                return true;
            }

            // Check whether any of the compared objects is null.
            if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
            {
                return false;
            }

            // Check whether the products' properties are equal.
            return x.Id == y.Id;
        }

        // If Equals() returns true for a pair of objects 
        // then GetHashCode() must return the same value for these objects.
        public int GetHashCode(UserModel userModel)
        {
            // Check whether the object is null
            if (ReferenceEquals(userModel, null)) return 0;

            // Calculate the hash code for UserModel.Id
            return userModel.Id.GetHashCode();
        }

    }
}